Parameters
- buffer
- An array of bytes.
- offset
- The zero-based byte offset in the buffer.
- count
- The amount of bytes to be written to the current stream.
Note that writing data to OracleLob object results in immediate data transfer to server.
public void UploadBlob(OracleConnection myConnection) { FileStream fs = new FileStream("D:\\Tmp\\_Water.bmp", FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); myConnection.Open(); OracleLob myLob = new OracleLob(myConnection,OracleDbType.Blob); int streamLength = (int)fs.Length; myLob.Write(r.ReadBytes(streamLength), 0, streamLength); OracleCommand myCommand = new OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection); OracleParameter myParam = myCommand.Parameters.Add("Pictures", OracleDbType.Blob); myParam.OracleValue = myLob; try { Console.WriteLine(myCommand.ExecuteNonQuery() + " rows affected."); } finally { myConnection.Close(); r.Close(); fs.Close(); } }
Public Sub UploadBlob(ByVal myConnection As OracleConnection) Dim fs As FileStream = New FileStream("D:\Tmp\_Water.bmp", FileMode.Open, FileAccess.Read) Dim r As BinaryReader = New BinaryReader(fs) myConnection.Open() Dim myLob As OracleLob = New OracleLob(myConnection, OracleDbType.Blob) Dim streamLength As Int32 = fs.Length myLob.Write(r.ReadBytes(streamLength), 0, streamLength) Dim myCommand As OracleCommand = New OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection) Dim myParam As OracleParameter = myCommand.Parameters.Add("Pictures", OracleDbType.Blob) myParam.OracleValue = myLob Try Console.WriteLine(myCommand.ExecuteNonQuery() & " rows affected.") Finally myConnection.Close() r.Close() fs.Close() End Try End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2